<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="{$Think.const.index_tpl}/css/css.css" rel="stylesheet" type="text/css" /> 
        <script type="text/javascript" src="{$Think.const.index_tpl}/js/jquery.min.js"></script>
        <script type="text/javascript" src="{$Think.const.index_tpl}/js/jquery.SuperSlide.2.1.1.js"></script>
        <script src="{$Think.const.index_tpl}/js/layer.js"></script>
        <script src="{$Think.const.index_tpl}/js/ajaxfileupload.js"></script>
        <title>{:cfg('name')}登录</title>
    </head>
    <body class="bj_ff">
        <div class="dltop">
            <div class="nr">
                <a href="/" title=""><img src="{$Think.const.index_tpl}/images/logo.png" width="175" height="93" alt=""></a> 
            </div>
        </div>
        <div class="dlnr">
            <div class="dlfp">
                <div class="nr">
                    <div class="dlys slideTxtBox">
                        <div class="pf_dlli hd">
                            <ul>
                                <li onclick="to_url('/index/logins/index/')" class="on">登录</li>
                                <li onclick="to_url('/index/registers/index/')">注册</li>
                            </ul>
                        </div>
                        <div class="db_dlys bd" id="root">
                            <div class="nrb">
                                <div class="lib_dl">
                                    <div class="libnr">
                                        <div class="lf"><img src="{$Think.const.index_tpl}/images/li1.jpg" width="41" height="39" alt=""></div>
                                        <div class="rf">
                                            <input type="text" name="user" id="user" placeholder="请输入用户名" class="inputa"  >
                                        </div>
                                    </div>
                                </div>
                                <div class="lib_dl">
                                    <div class="libnr">
                                        <div class="lf"><img src="{$Think.const.index_tpl}/images/li2.jpg" width="41" height="39" alt=""></div>
                                        <div class="rf">
                                            <input type="password" name="pwd" id="pwd" placeholder="请输入密码" class="inputa"  >
                                        </div>
                                    </div>
                                </div>
                                <div class="lib_dl">
                                    <div class="libnr">
                                        <div class="lf"><img src="{$Think.const.index_tpl}/images/li3.jpg" width="41" height="39" alt=""></div>
                                        <div class="rfc"><input type="text" name="code" id="code" placeholder="请输入验证码"></div>
                                    </div>
                                    <div class="rfb"><img id="code_img" src="{:url('/admin/index/verify');}"></div>
                                </div>
                                <div class="wjmm"><a href="/index/logins/forget/" title="">忘记密码？</a></div>
                                <div class="dl_an">
                                    <input type="submit" name="button" id="button" value="登录" onclick="ajax_post()" class="an_dl">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="dl_dbwz">{:cfg('copyright')}</div>
        
        <script>
            var root = document.getElementById('root');
//            如果是添加到root元素上，则只能是聚焦到input中，回车才触发keyup事件
            root.addEventListener('keyup', function(e){
                console.log(e)
                if(e.keyCode == '13'){
                    ajax_post();
                }
            });
        </script>
        <script>
            function to_url(urls)
            {
                location.href = urls;
            }
            //验证码
            $("#code_img").click(function () {
                $("#code_img").attr('src', "{:url('/admin/index/verify');}")
            });
            //ajax提交
            function ajax_post()
            {
                var post = {};
                post.user = $("#user").val();
                post.code = $("#code").val();
                post.pwd = $("#pwd").val();

                $.post("/index/logins/login_submit/", post, function (data)
                {
                    if (data.status == 1)
                    {
                        layer.msg(data.msg, {
                            time: 2000
                        }, function () {
                            location.href = data.data.url;
                        });
                    }
                    else
                    {
                        layer.msg(data.msg);
                        $("#code_img").attr('src', "{:url('/admin/index/verify');}")
                    }
                }, 'json');
            }
           $("body").keydown(function() {
            if (event.keyCode == "13") {//keyCode=13是回车键
                    $('#button').click();
                };
            });
        </script>
    </body>
</html>